﻿<%@ WebHandler Language="C#" Class="Proxy" %>

using System;
using System.Web;


public class Proxy : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
       // context.Response.ContentType = "text/plain";

        context.Response.Charset = "utf-8";
        context.Response.ContentType = "application/json";

        System.Web.SessionState.HttpSessionState Session = context.Session;
        
        string op = context.Request.Params["op"];
        
        //context.Response.Write(op);



        var request = context.Request;
        var response = context.Response;
        response.Charset = "utf-8";
        response.ContentType = "application/json";

        //if (Session["userid"] == null)
        //{
        //    response.Write("{\"offLine\":1}");
        //    response.End();
        //    return;
        //}
        //int userid = int.Parse(Session["userid"].ToString());
        
        //parkMSysHeader wsHeader = new parkMSysHeader();
        //wsHeader.UserName = "";
        //wsHeader.UserPwd = "";

       // ServiceList ws = new ServiceList();
        //ws.parkMSysHeaderValue = wsHeader;
        
        
        string json = "{}";

        switch (op)
        {
            case "ListUser":
                {
                   // json = ListUser(ws,request);
                    break;
                }
            case "AddUser":
                {
                  //  json = AddUser(ws, request);
                    break;
                }
            case "EditUser":
                {
                   // json = EditUser(ws,request);
                    break; 
                }
            case "DelUser":
                {
                   // json = DelUser(ws,request);
                    break;
                }
            case "ListDept":
                {
                   // json = ListDept(ws);
                    break; 
                }
            case "ListJobByDept":
                {
                   // json = ListJobByDept(ws,request);
                    break;
                }
            case "ListRole":
                {
                   // json = ListRole(ws);
                    break;
                }
            case "GetUserInfoById":
                {
                  //  json = GetUserInfoById(ws,request);
                    break;
                }
            case "ShowUserPrivilege":
                {
                   // json = ShowUserPrivilege(ws,request);
                    break; 
                }
        }


        response.Write(json);
        response.End();
    }

    /*
    /// <summary>
    /// 获取用户列表
    /// </summary>
    /// <param name="wservices"></param>
    /// <param name="Request"></param>
    /// <returns></returns>
    private string ListUser(ServiceList wservices, HttpRequest Request)
    {
        string json = "{}";

        int deptId = string.IsNullOrEmpty(Request.Params["deptId"]) ? 0 : int.Parse(Request.Params["deptId"]);
        int jobId = string.IsNullOrEmpty(Request.Params["jobId"]) ? 0 : int.Parse(Request.Params["jobId"]);        
        int userId = string.IsNullOrEmpty(Request.Params["userId"]) ? 0 : int.Parse(Request.Params["userId"]);
        string loginName = Request.Params["loginName"];
        string username = Request.Params["username"];
        int page = string.IsNullOrEmpty(Request.Params["page"]) ? 1 : int.Parse(Request.Params["page"]);
        int size = string.IsNullOrEmpty(Request.Params["size"]) ? 20 : int.Parse(Request.Params["size"]);

        json = wservices.ListUser(deptId, jobId, userId, loginName, username,page,size);
        return json;
    }
    
    /// <summary>
    /// 获取用户列表
    /// </summary>
    /// <param name="wservices"></param>
    /// <param name="Request"></param>
    /// <returns></returns>
    private string GetUserInfoById(ServiceList wservices, HttpRequest Request)
    {
        string json = "{}";

        int userId = string.IsNullOrEmpty(Request.Params["userId"]) ? 0 : int.Parse(Request.Params["userId"]);
        json = wservices.GetUserInfoById(userId);
        return json;
    }
    
    /// <summary>
    /// 添加用户
    /// </summary>
    /// <param name="wservices"></param>
    /// <param name="Request"></param>
    /// <returns></returns>
    private string AddUser(ServiceList wservices, HttpRequest Request)
    {
        string json = "{}";

        int deptId = string.IsNullOrEmpty(Request.Params["deptId"]) ? 0 : int.Parse(Request.Params["deptId"]);
        int jobId = string.IsNullOrEmpty(Request.Params["jobId"]) ? 0 : int.Parse(Request.Params["jobId"]);
        int roleId = string.IsNullOrEmpty(Request.Params["roleId"]) ? 0 : int.Parse(Request.Params["roleId"]);
        string loginName = Request.Params["loginName"];
        string username = Request.Params["username"];
        string gender = Request.Params["gender"];
        string IDNo = Request.Params["IDNo"];
        string phone = Request.Params["phone"];
        string userPhoto = Request.Params["userPhoto"];

        json = wservices.AddUser(deptId, jobId, roleId,  loginName, username, gender, IDNo, phone, userPhoto);
        return json;
    }
    
    /// <summary>
    /// 修改用户
    /// </summary>
    /// <param name="wservices"></param>
    /// <param name="Request"></param>
    /// <returns></returns>
    private string EditUser(ServiceList wservices, HttpRequest Request)
    {
        string json = "{}";

        int deptId = string.IsNullOrEmpty(Request.Params["deptId"]) ? 0 : int.Parse(Request.Params["deptId"]);
        int jobId = string.IsNullOrEmpty(Request.Params["jobId"]) ? 0 : int.Parse(Request.Params["jobId"]);
        int roleId = string.IsNullOrEmpty(Request.Params["roleId"]) ? 0 : int.Parse(Request.Params["roleId"]);
        int userId = string.IsNullOrEmpty(Request.Params["userId"]) ? 0 : int.Parse(Request.Params["userId"]);
        string loginName = Request.Params["loginName"];
        string username = Request.Params["username"];
        string gender = Request.Params["gender"];
        string IDNo = Request.Params["IDNo"];
        string phone = Request.Params["phone"];
        string userPhoto = Request.Params["userPhoto"];

        json = wservices.EditUser(deptId, jobId, roleId, userId, loginName, username, gender, IDNo, phone, userPhoto);
        return json;
    }
    /// <summary>
    /// 删除用户
    /// </summary>
    /// <param name="wservices"></param>
    /// <param name="Request"></param>
    /// <returns></returns>
    private string DelUser(ServiceList wservices, HttpRequest Request)
    {
        string json = "{}";
        int userId = string.IsNullOrEmpty(Request.Params["userId"]) ? 0 : int.Parse(Request.Params["userId"]);
        json = wservices.DelUser(userId);
        return json;
    }
    /// <summary>
    /// 获取部门列表
    /// </summary>
    /// <param name="wservices"></param>
    /// <returns></returns>
    private string ListDept(ServiceList wservices)
    {
        string json = "{}";        
        json = wservices.ListDept();
        return json;
    }
    /// <summary>
    /// 获取岗位列表
    /// </summary>
    /// <param name="wservices"></param>
    /// <param name="Request"></param>
    /// <returns></returns>
    private string ListJobByDept(ServiceList wservices, HttpRequest Request)
    {
        string json = "{}";
        int dept_id = string.IsNullOrEmpty(Request.Params["dept_id"]) ? 0 : int.Parse(Request.Params["dept_id"]);
        json = wservices.ListJobByDept(dept_id);
        return json;
    }
    /// <summary>
    /// 获取角色列表
    /// </summary>
    /// <param name="wservices"></param>
    /// <returns></returns>
    private string ListRole(ServiceList wservices)
    {
        string json = "{}";
        json = wservices.ListRole();
        return json;
    }
    
    /// <summary>
    /// 获取个人权限列表
    /// </summary>
    /// <param name="wservices"></param>
    /// <param name="Request"></param>
    /// <returns></returns>
    private string ShowUserPrivilege(ServiceList wservices, HttpRequest Request)
    {
        string json = "{}";
        int userId = string.IsNullOrEmpty(Request.Params["userId"]) ? 0 : int.Parse(Request.Params["userId"]);
        string loginName = Request.Params["loginName"];
        string name = Request.Params["name"];
        // int userId, int loginName, int name
        json = wservices.ShowUserPrivilege(userId,loginName,name);
        return json;
    }
    */


    public bool IsReusable {
        get {
            return false;
        }
    }
}